package com.blog.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blog.entity.Admin;
import com.blog.service.AdminService;
import com.blog.service.Impl.AdminServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;


@WebServlet("/AdminLogin.do")
public class AdminLoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		AdminService as = new AdminServiceImpl();
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		response.setContentType("application/json;charset=utf-8");
		Admin admin = new Admin();
		admin.setAdminName(username);
		admin.setAdminPass(password);
		new ObjectMapper().writeValue(response.getWriter(), as.selectAdminByName(admin));
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
